{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Preprocessing of IRefIndex protein-protein interaction network\n",
    "This notebook processes the raw [IRefIndex](http://irefindex.org/wiki/index.php?title=iRefIndex) PPI network downloaded from [here](http://irefindex.org/download/irefindex/data/archive/release_15.0/psi_mitab/MITAB2.6/9606.mitab.22012018.txt.zip). I used the release `v15.0` for the analysis.\n",
    "\n",
    "Preprocessing involved:\n",
    "\n",
    "* Selecting only binary interactions (and no self-interactions)\n",
    "* Selecting only human interactions\n",
    "* Converting IDs to ensembl IDs and hugo gene symbols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import mygene"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "IREF_interactions = pd.read_csv('../data/networks/IREF_9606.mitab.22012018.txt.zip',\n",
    "                                sep='\\t', compression='zip')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    uniprotkb:A0A024RB96\n",
       "1        uniprotkb:P40616\n",
       "2        uniprotkb:Q9NVH1\n",
       "3        uniprotkb:P29459\n",
       "4        uniprotkb:Q5HYI7\n",
       "Name: #uidA, dtype: object"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IREF_binary_interactions = IREF_interactions[IREF_interactions.edgetype == 'X'] # only binary and non-self interactions\n",
    "IREF_humanbinary = IREF_binary_interactions[IREF_binary_interactions.taxa == 'taxid:9606(Homo sapiens)'] # only human interactions\n",
    "IREF_humanbinary['#uidA'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "querying 1-1000...done.\n",
      "querying 1001-2000...done.\n",
      "querying 2001-3000...done.\n",
      "querying 3001-4000...done.\n",
      "querying 4001-5000...done.\n",
      "querying 5001-6000...done.\n",
      "querying 6001-7000...done.\n",
      "querying 7001-8000...done.\n",
      "querying 8001-9000...done.\n",
      "querying 9001-10000...done.\n",
      "querying 10001-11000...done.\n",
      "querying 11001-12000...done.\n",
      "querying 12001-13000...done.\n",
      "querying 13001-14000...done.\n",
      "querying 14001-15000...done.\n",
      "querying 15001-16000...done.\n",
      "querying 16001-17000...done.\n",
      "querying 17001-18000...done.\n",
      "querying 18001-19000...done.\n",
      "querying 19001-20000...done.\n",
      "querying 20001-21000...done.\n",
      "querying 21001-22000...done.\n",
      "querying 22001-23000...done.\n",
      "querying 23001-24000...done.\n",
      "querying 24001-25000...done.\n",
      "querying 25001-26000...done.\n",
      "querying 26001-27000...done.\n",
      "querying 27001-28000...done.\n",
      "querying 28001-29000...done.\n",
      "querying 29001-30000...done.\n",
      "querying 30001-31000...done.\n",
      "querying 31001-32000...done.\n",
      "querying 32001-33000...done.\n",
      "querying 33001-34000...done.\n",
      "querying 34001-35000...done.\n",
      "querying 35001-36000...done.\n",
      "querying 36001-37000...done.\n",
      "querying 37001-37967...done.\n",
      "Finished.\n",
      "197 input query terms found dup hits:\n",
      "\t[('Q9BWG6', 2), ('B4DJ51', 3), ('P68431', 10), ('O15263', 2), ('A4FTV9', 5), ('Q71DI3', 3), ('Q8IYR6\n",
      "16908 input query terms found no hit:\n",
      "\t['YIObZESYCgvbrAtwjaW/TlaJ1G09606', 'P17813-2', 'Q9TNN7', 'O43889-2', 'Q5JZY3-3', 'GmH4x/SHgF8699HTK\n"
     ]
    }
   ],
   "source": [
    "def get_gene_symbols_for_IREF(list_of_ensembl_ids):\n",
    "    # get Ensembl IDs for gene names\n",
    "    mg = mygene.MyGeneInfo()\n",
    "    res = mg.querymany(list_of_ensembl_ids,\n",
    "                       scopes='refseq,symbol,entrezgene,reporter,uniprot',\n",
    "                       fields='symbol',\n",
    "                       species='human', returnall=True\n",
    "                      )\n",
    "\n",
    "    def get_symbol_and_ensembl(d):\n",
    "        if 'symbol' in d:\n",
    "            return [d['query'], d['symbol']]\n",
    "        else:\n",
    "            return [d['query'], None]\n",
    "\n",
    "    node_names = [get_symbol_and_ensembl(d) for d in res['out']]\n",
    "    # now, retrieve the names and IDs from a dictionary and put in DF\n",
    "    node_names = pd.DataFrame(node_names, columns=['Ensembl_ID', 'Symbol']).set_index('Ensembl_ID')\n",
    "    node_names.dropna(axis=0, inplace=True)\n",
    "    return node_names\n",
    "\n",
    "all_ids = IREF_humanbinary['#uidA'].append(IREF_humanbinary.uidB).unique()\n",
    "all_ids = [i.split(':')[1] for i in all_ids] # remove the trailing database where the interaction comes from\n",
    "iref_id_mapping = get_gene_symbols_for_IREF(all_ids)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/sasse/anaconda3/lib/python3.7/site-packages/ipykernel/__main__.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  if __name__ == '__main__':\n",
      "/home/sasse/anaconda3/lib/python3.7/site-packages/ipykernel/__main__.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  from ipykernel import kernelapp as app\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>#uidA</th>\n",
       "      <th>uidB</th>\n",
       "      <th>altA</th>\n",
       "      <th>altB</th>\n",
       "      <th>aliasA</th>\n",
       "      <th>aliasB</th>\n",
       "      <th>method</th>\n",
       "      <th>author</th>\n",
       "      <th>pmids</th>\n",
       "      <th>taxa</th>\n",
       "      <th>...</th>\n",
       "      <th>crogidb</th>\n",
       "      <th>crigid</th>\n",
       "      <th>icrogida</th>\n",
       "      <th>icrogidb</th>\n",
       "      <th>icrigid</th>\n",
       "      <th>imex_id</th>\n",
       "      <th>edgetype</th>\n",
       "      <th>numParticipants</th>\n",
       "      <th>Symbol</th>\n",
       "      <th>Symbol_p2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0A024RB96</td>\n",
       "      <td>A0A024RA90</td>\n",
       "      <td>entrezgene/locuslink:196403|refseq:NP_00127317...</td>\n",
       "      <td>entrezgene/locuslink:51619|refseq:NP_057067|un...</td>\n",
       "      <td>hgnc:DTX3|uniprotkb:A0A024RB96_HUMAN|uniprotkb...</td>\n",
       "      <td>hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...</td>\n",
       "      <td>psi-mi:\"MI:0018\"(two hybrid)</td>\n",
       "      <td>Markson G (2009)</td>\n",
       "      <td>pubmed:19549727</td>\n",
       "      <td>taxid:9606(Homo sapiens)</td>\n",
       "      <td>...</td>\n",
       "      <td>xc+Dyvh3gHK14B0RxgVqoToxbTI9606</td>\n",
       "      <td>+4O62gRrUCSHLPbxlq5d/Xm4zU0</td>\n",
       "      <td>3006542</td>\n",
       "      <td>4831700</td>\n",
       "      <td>617977</td>\n",
       "      <td>-</td>\n",
       "      <td>X</td>\n",
       "      <td>2</td>\n",
       "      <td>DTX3</td>\n",
       "      <td>UBE2D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>A0A024RB96</td>\n",
       "      <td>A0A024RA90</td>\n",
       "      <td>entrezgene/locuslink:196403|refseq:NP_00127317...</td>\n",
       "      <td>entrezgene/locuslink:51619|refseq:NP_057067|un...</td>\n",
       "      <td>hgnc:DTX3|uniprotkb:A0A024RB96_HUMAN|uniprotkb...</td>\n",
       "      <td>hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...</td>\n",
       "      <td>psi-mi:\"MI:0397\"(two hybrid array)</td>\n",
       "      <td>markson-2009-2</td>\n",
       "      <td>pubmed:19549727</td>\n",
       "      <td>taxid:9606(Homo sapiens)</td>\n",
       "      <td>...</td>\n",
       "      <td>xc+Dyvh3gHK14B0RxgVqoToxbTI9606</td>\n",
       "      <td>+4O62gRrUCSHLPbxlq5d/Xm4zU0</td>\n",
       "      <td>3006542</td>\n",
       "      <td>4831700</td>\n",
       "      <td>617977</td>\n",
       "      <td>-</td>\n",
       "      <td>X</td>\n",
       "      <td>2</td>\n",
       "      <td>DTX3</td>\n",
       "      <td>UBE2D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642337</th>\n",
       "      <td>O75360</td>\n",
       "      <td>A0A024RA90</td>\n",
       "      <td>entrezgene/locuslink:5626|uniprotkb:O75360|rog...</td>\n",
       "      <td>entrezgene/locuslink:51619|refseq:NP_057067|un...</td>\n",
       "      <td>hgnc:PROP1|uniprotkb:PROP1_HUMAN|crogid:SzGxUv...</td>\n",
       "      <td>hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...</td>\n",
       "      <td>psi-mi:\"MI:1112\"(two hybrid prey pooling appro...</td>\n",
       "      <td>huri-2017-1</td>\n",
       "      <td>-</td>\n",
       "      <td>taxid:9606(Homo sapiens)</td>\n",
       "      <td>...</td>\n",
       "      <td>xc+Dyvh3gHK14B0RxgVqoToxbTI9606</td>\n",
       "      <td>57YM6UrS02SV7ivsxQ3fuKCzBIE</td>\n",
       "      <td>14007438</td>\n",
       "      <td>4831700</td>\n",
       "      <td>1774651</td>\n",
       "      <td>-</td>\n",
       "      <td>X</td>\n",
       "      <td>2</td>\n",
       "      <td>PROP1</td>\n",
       "      <td>UBE2D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642343</th>\n",
       "      <td>O75360</td>\n",
       "      <td>A0A024RA90</td>\n",
       "      <td>entrezgene/locuslink:5626|uniprotkb:O75360|rog...</td>\n",
       "      <td>entrezgene/locuslink:51619|refseq:NP_057067|un...</td>\n",
       "      <td>hgnc:PROP1|uniprotkb:PROP1_HUMAN|crogid:SzGxUv...</td>\n",
       "      <td>hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...</td>\n",
       "      <td>psi-mi:\"MI:1112\"(two hybrid prey pooling appro...</td>\n",
       "      <td>huri-2017-1</td>\n",
       "      <td>-</td>\n",
       "      <td>taxid:9606(Homo sapiens)</td>\n",
       "      <td>...</td>\n",
       "      <td>xc+Dyvh3gHK14B0RxgVqoToxbTI9606</td>\n",
       "      <td>57YM6UrS02SV7ivsxQ3fuKCzBIE</td>\n",
       "      <td>14007438</td>\n",
       "      <td>4831700</td>\n",
       "      <td>1774651</td>\n",
       "      <td>-</td>\n",
       "      <td>X</td>\n",
       "      <td>2</td>\n",
       "      <td>PROP1</td>\n",
       "      <td>UBE2D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642411</th>\n",
       "      <td>O75360</td>\n",
       "      <td>A0A024RA90</td>\n",
       "      <td>entrezgene/locuslink:5626|uniprotkb:O75360|rog...</td>\n",
       "      <td>entrezgene/locuslink:51619|refseq:NP_057067|un...</td>\n",
       "      <td>hgnc:PROP1|uniprotkb:PROP1_HUMAN|crogid:SzGxUv...</td>\n",
       "      <td>hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...</td>\n",
       "      <td>psi-mi:\"MI:0397\"(two hybrid array)</td>\n",
       "      <td>huri-2017-2</td>\n",
       "      <td>-</td>\n",
       "      <td>taxid:9606(Homo sapiens)</td>\n",
       "      <td>...</td>\n",
       "      <td>xc+Dyvh3gHK14B0RxgVqoToxbTI9606</td>\n",
       "      <td>57YM6UrS02SV7ivsxQ3fuKCzBIE</td>\n",
       "      <td>14007438</td>\n",
       "      <td>4831700</td>\n",
       "      <td>1774651</td>\n",
       "      <td>-</td>\n",
       "      <td>X</td>\n",
       "      <td>2</td>\n",
       "      <td>PROP1</td>\n",
       "      <td>UBE2D4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 56 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             #uidA        uidB  \\\n",
       "0       A0A024RB96  A0A024RA90   \n",
       "606     A0A024RB96  A0A024RA90   \n",
       "642337      O75360  A0A024RA90   \n",
       "642343      O75360  A0A024RA90   \n",
       "642411      O75360  A0A024RA90   \n",
       "\n",
       "                                                     altA  \\\n",
       "0       entrezgene/locuslink:196403|refseq:NP_00127317...   \n",
       "606     entrezgene/locuslink:196403|refseq:NP_00127317...   \n",
       "642337  entrezgene/locuslink:5626|uniprotkb:O75360|rog...   \n",
       "642343  entrezgene/locuslink:5626|uniprotkb:O75360|rog...   \n",
       "642411  entrezgene/locuslink:5626|uniprotkb:O75360|rog...   \n",
       "\n",
       "                                                     altB  \\\n",
       "0       entrezgene/locuslink:51619|refseq:NP_057067|un...   \n",
       "606     entrezgene/locuslink:51619|refseq:NP_057067|un...   \n",
       "642337  entrezgene/locuslink:51619|refseq:NP_057067|un...   \n",
       "642343  entrezgene/locuslink:51619|refseq:NP_057067|un...   \n",
       "642411  entrezgene/locuslink:51619|refseq:NP_057067|un...   \n",
       "\n",
       "                                                   aliasA  \\\n",
       "0       hgnc:DTX3|uniprotkb:A0A024RB96_HUMAN|uniprotkb...   \n",
       "606     hgnc:DTX3|uniprotkb:A0A024RB96_HUMAN|uniprotkb...   \n",
       "642337  hgnc:PROP1|uniprotkb:PROP1_HUMAN|crogid:SzGxUv...   \n",
       "642343  hgnc:PROP1|uniprotkb:PROP1_HUMAN|crogid:SzGxUv...   \n",
       "642411  hgnc:PROP1|uniprotkb:PROP1_HUMAN|crogid:SzGxUv...   \n",
       "\n",
       "                                                   aliasB  \\\n",
       "0       hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...   \n",
       "606     hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...   \n",
       "642337  hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...   \n",
       "642343  hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...   \n",
       "642411  hgnc:UBE2D4|uniprotkb:A0A024RA90_HUMAN|uniprot...   \n",
       "\n",
       "                                                   method            author  \\\n",
       "0                            psi-mi:\"MI:0018\"(two hybrid)  Markson G (2009)   \n",
       "606                    psi-mi:\"MI:0397\"(two hybrid array)    markson-2009-2   \n",
       "642337  psi-mi:\"MI:1112\"(two hybrid prey pooling appro...       huri-2017-1   \n",
       "642343  psi-mi:\"MI:1112\"(two hybrid prey pooling appro...       huri-2017-1   \n",
       "642411                 psi-mi:\"MI:0397\"(two hybrid array)       huri-2017-2   \n",
       "\n",
       "                  pmids                      taxa  ...  \\\n",
       "0       pubmed:19549727  taxid:9606(Homo sapiens)  ...   \n",
       "606     pubmed:19549727  taxid:9606(Homo sapiens)  ...   \n",
       "642337                -  taxid:9606(Homo sapiens)  ...   \n",
       "642343                -  taxid:9606(Homo sapiens)  ...   \n",
       "642411                -  taxid:9606(Homo sapiens)  ...   \n",
       "\n",
       "                                crogidb                       crigid  \\\n",
       "0       xc+Dyvh3gHK14B0RxgVqoToxbTI9606  +4O62gRrUCSHLPbxlq5d/Xm4zU0   \n",
       "606     xc+Dyvh3gHK14B0RxgVqoToxbTI9606  +4O62gRrUCSHLPbxlq5d/Xm4zU0   \n",
       "642337  xc+Dyvh3gHK14B0RxgVqoToxbTI9606  57YM6UrS02SV7ivsxQ3fuKCzBIE   \n",
       "642343  xc+Dyvh3gHK14B0RxgVqoToxbTI9606  57YM6UrS02SV7ivsxQ3fuKCzBIE   \n",
       "642411  xc+Dyvh3gHK14B0RxgVqoToxbTI9606  57YM6UrS02SV7ivsxQ3fuKCzBIE   \n",
       "\n",
       "        icrogida icrogidb  icrigid imex_id edgetype numParticipants Symbol  \\\n",
       "0        3006542  4831700   617977       -        X               2   DTX3   \n",
       "606      3006542  4831700   617977       -        X               2   DTX3   \n",
       "642337  14007438  4831700  1774651       -        X               2  PROP1   \n",
       "642343  14007438  4831700  1774651       -        X               2  PROP1   \n",
       "642411  14007438  4831700  1774651       -        X               2  PROP1   \n",
       "\n",
       "       Symbol_p2  \n",
       "0         UBE2D4  \n",
       "606       UBE2D4  \n",
       "642337    UBE2D4  \n",
       "642343    UBE2D4  \n",
       "642411    UBE2D4  \n",
       "\n",
       "[5 rows x 56 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IREF_humanbinary['#uidA'] = [i[1] for i in IREF_humanbinary['#uidA'].str.split(':')]\n",
    "IREF_humanbinary['uidB'] = [i[1] for i in IREF_humanbinary['uidB'].str.split(':')]\n",
    "p1_incl = IREF_humanbinary.join(iref_id_mapping, on='#uidA', how='inner', rsuffix='_p1')\n",
    "both_incl = p1_incl.join(iref_id_mapping, on='uidB', how='inner', rsuffix='_p2')\n",
    "both_incl.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/sasse/anaconda3/lib/python3.7/site-packages/ipykernel/__main__.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  from ipykernel import kernelapp as app\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>partner1</th>\n",
       "      <th>partner2</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>DTX3</td>\n",
       "      <td>UBE2D4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>606</th>\n",
       "      <td>DTX3</td>\n",
       "      <td>UBE2D4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642337</th>\n",
       "      <td>PROP1</td>\n",
       "      <td>UBE2D4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642343</th>\n",
       "      <td>PROP1</td>\n",
       "      <td>UBE2D4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642411</th>\n",
       "      <td>PROP1</td>\n",
       "      <td>UBE2D4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       partner1 partner2  confidence\n",
       "0          DTX3   UBE2D4           1\n",
       "606        DTX3   UBE2D4           1\n",
       "642337    PROP1   UBE2D4           1\n",
       "642343    PROP1   UBE2D4           1\n",
       "642411    PROP1   UBE2D4           1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IREF_ppi_final = both_incl[['Symbol', 'Symbol_p2']]\n",
    "IREF_ppi_final['confidence'] = 1\n",
    "IREF_ppi_final.columns = ['partner1', 'partner2', 'confidence']\n",
    "IREF_ppi_final.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Duplicated Edges: 457567 -> New #Edges: 383640\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/sasse/anaconda3/lib/python3.7/site-packages/ipykernel/__main__.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  from ipykernel import kernelapp as app\n"
     ]
    }
   ],
   "source": [
    "num_duplicated_edges = IREF_ppi_final.duplicated(subset=['partner1', 'partner2']).sum()\n",
    "IREF_ppi_final.drop_duplicates(subset=['partner1', 'partner2'], inplace=True)\n",
    "print (\"Duplicated Edges: {} -> New #Edges: {}\".format(num_duplicated_edges,\n",
    "                                                       IREF_ppi_final.shape[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "IREF_ppi_final.to_csv('../data/networks/IREF_symbols_20190730.tsv',\n",
    "                      sep='\\t', compression='gzip')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
